<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>所有用户信息</title>
</head>
<body>
	<center>
		<h3>所有用户信息</h3>
		<table border="1">
			<tr>
				<th>账户</th>
				<th>密码</th>
			</tr>
			<%
			//加载、注册数据库驱动程序
			Class.forName("com.mysql.cj.jdbc.Driver");
 
			//数据库连接字符串
			String url = "jdbc:mysql://localhost:3306/db";
			//用户名
			String username = "root";
			//密码
			String password = "root";
			//数据库连接
			Connection conn = DriverManager.getConnection(url, username, password);
			//构造sql语句
			String sql = "select * from user";
			//获取数据库操作对象（PreparedStatement对象）
			PreparedStatement pstmt = conn.prepareStatement(sql);
 
			ResultSet rs = pstmt.executeQuery();
 
			//循环前准备变量
			String uname = null;
			String upassword = null;
			while (rs.next()) {
				uname = rs.getString("username");
				upassword = rs.getString("password");
			%>
			<tr>
				<td><%=uname%></td>
				<th><%=upassword%></th>
			</tr>
 
			<%
			}
			//释放对象
			if (pstmt != null) {
			pstmt.close();
			}
			if (conn != null) {
			pstmt.close();
			}
			if (rs != null) {
			rs.close();
			}
			%>
			</center>
		</table>
</body>
</html>